package com.kk.rbac.controller;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.kk.rbac.Vo.Router;
import com.kk.rbac.Vo.UserInfo;
import com.kk.rbac.Vo.UserLogin;
import com.kk.rbac.common.R;
import com.kk.rbac.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : K k
 * @date : 18:01 2020/11/4
 */
@RestController
@RequestMapping("user")
@CrossOrigin
public class UserController {

    @Autowired
    private MenuService menuService;

    @PostMapping("login")
    public R login(@RequestBody UserLogin userLogin){
        return R.ok("返回token信息").data("token","admin-token");
    }

    @GetMapping("info")
    public R userInfo(String token){
        System.out.println("获取用户信息，前端接收到的token："+token);
        UserInfo userInfo = new UserInfo();
        userInfo.setName("kk").setAvatar("https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif")
                .setRoles("Admin");
        return R.ok("用户信息").data("userInfo",userInfo);
    }

    @GetMapping("getMenu")
    public R getMenu(){
        //后期根据security获取对应用户
        List<Router> routers=menuService.getRouterByUser();
        return R.ok("路由表").data("routers",routers);
    }

    @PostMapping("logout")
    public R logout(){
        return R.ok();
    }
}
